/* eslint-disable no-console */
import { migrator, seeder } from './umzug';

const initDatabase = async () => {
  try {
    await seeder.down({ to: 0 });
    console.log('清除数据成功');
    await migrator.down({ to: 0 });
    console.log('清除数据表成功');
    await migrator.up();
    console.log('创建数据表成功');
    await seeder.up();
    console.log('填充数据成功');
  } catch (error) {
    console.error('数据库初始化失败');
  }
};

export default initDatabase;
